<?php
// +----------------------------------------------------------------------
// | ManniuRead
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://manniuyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: heitao <read@manniuyun.com>
// +----------------------------------------------------------------------

namespace app\member\validate;

use think\Validate;

class Member extends Validate{

    protected $rule = [
        'username'      => ['require','unique' => 'member','chsAlphaNum','min' => 6,'max' => 16,'token'],
        'password'      => ['require','alphaDash','min' =>6, 'max' => 20],
        'captcha_code'  => ['require','captcha'],
        'nickname'      => ['unique' => 'member','min' => 2,'max' => 15],
        'mobile'        => ['unique' => 'member','number','length' => 11],
        'email'         => ['unique' => 'member','email']
    ];

    protected $message  =   [
        'username.require'      => '用户名不能为空',
        'username.unique'       => '用户名已存在',
        'username.chsAlphaNum'  => '用户名只能是汉字、字母和数字',
        'username.min'          => '用户名长度不能少于6个字符',
        'username.max'          => '用户名长度不能多于16个字符',

        'password.require'      => '密码不能为空',
        'password.alphaDash'    => '密码只能是字母和数字，下划线 _ 及破折号 -',
        'password.different'    => '两次输入的密码不同',
        'password.min'          => '密码长度不能少于6个字符',
        'password.max'          => '密码长度不能多于20个字符',

        'nickname.unique'       => '昵称已存在',
        'nickname.min'          => '昵称长度不能小于2个字符',
        'nickname.max'          => '昵称长度不能大于15个字符',

        'mobile.unique'          => '手机号已存在',
        'mobile.number'          => '手机号必须为数字',
        'mobile.length'          => '手机号必须为11位',

        'email.unique'          => '邮箱已存在',
        'email.email'           => '邮箱格式错误',
    ];

    protected $scene = [
        'edit'  => [
            'password'  => ['min'=>6,'max'=>20],
            'nickname'  => ['min'=>2,'max'=>15],
            'phone'     => ['number','length'=>11],
            'email'     => ['email'],
        ],
        'admin_add' => [
            'username' => ['require','unique' => 'member','chsAlphaNum','min' => 6,'max' => 16],
            'password',
            'phone' => ['unique'=>'member','number','length'=>11],
            'email' => ['unique'=>'member','email'],
        ],
    ];

}